# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=ruamel.yaml.clib
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.2.7
pkgrel=3
pkgdesc='C version of reader, parser and emitter for ruamel.yaml derived from libyaml (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://sourceforge.net/projects/ruamel-yaml-clib/"
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://files.pythonhosted.org/packages/source/${_realname:0:1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('1f08fd5a2bea9c4180db71678e850b995d2a5f4537be0e94557668cf0f5f9497')

prepare() {
  rm -rf "python-build-${MSYSTEM}" | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"

  # clang build workaround
  # TODO: maybe cython regen would help too? but cython sources are not included in the tarball
  CFLAGS+=" -Wno-incompatible-function-pointer-types"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  RUAMEL_NO_PIP_INSTALL_CHECK=1 ${MINGW_PREFIX}/bin/python setup.py install \
    --prefix=${MINGW_PREFIX} --root="${pkgdir}" --optimize=1 --skip-build
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
